﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FirebirdSql.Data.FirebirdClient;

namespace University
{
  
   public partial class STUDENTS : University.LEARNERS
    {
        static string sqlSelect = "SELECT * FROM STUDENTS";
       FbDataAdapter da = new FbDataAdapter(sqlSelect,con);
        DataTable dt = new DataTable();

        public STUDENTS()
        {
            InitializeComponent();
           
        }
       public STUDENTS(TreeNode node, ContextMenuStrip s, string com, int id)
           : base(node, s, com, id)
        {
            InitializeComponent();
            node_id = Convert.ToInt32(mynode.Tag.ToString());
              da.Fill(dt); 
            bindingSource1.DataSource = dt;
            textBox6.DataBindings.Add("Text", bindingSource1, "PIK_VUPYSKY");
            richTextBox2.DataBindings.Add("Text", bindingSource1, "FACULTET");
            richTextBox3.DataBindings.Add("Text", bindingSource1, "KAFEDRA");
            richTextBox4.DataBindings.Add("Text", bindingSource1, "GRYPA");
            bindingSource1.Filter = "UNIQUE_NO =" + node_id;
            if (com == "Remove") { Remove("STUDENTS"); }
        }

        public override void Remove(string name)
        {
            base.Remove(name);
        }

        public override void UpdateForm()
        {
            OpenCon();
            UpdateFild("STUDENTS", "PIK_VUPYSKY", textBox6.Text);
            UpdateFild("STUDENTS", "FACULTET", richTextBox2.Text);
            UpdateFild("STUDENTS", "KAFEDRA", richTextBox3.Text);
            UpdateFild("STUDENTS", "GRYPA", richTextBox4.Text);
            base.UpdateForm();
        }
       public override void InsertFild(string klas)
       {
           OpenCon();
           FbCommand cmdInsert = new FbCommand("INSERT INTO STUDENTS(UNIQUE_NO,PIK_VUPYSKY,FACULTET,KAFEDRA,GRYPA) VALUES(@1,@2,@3,@4,@5)", con);
           cmdInsert.Parameters.AddWithValue("1", textBox1.Text);
           cmdInsert.Parameters.AddWithValue("2", textBox6.Text);
           cmdInsert.Parameters.AddWithValue("3", richTextBox2.Text);
           cmdInsert.Parameters.AddWithValue("4", richTextBox3.Text);
           cmdInsert.Parameters.AddWithValue("5", richTextBox4.Text);
           cmdInsert.ExecuteNonQuery();
           base.InsertFild(klas);
       }
       
        private void Students_Load(object sender, EventArgs e)
        {

        }
    }
}